﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using System.Data;

namespace BLL
{
    public class ConsumableManage
    {
        /// <summary>
        /// 新增一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(Model.Consumable model)
        {
            return ConsumableService.Add(model);
        }

        /// <summary>
        /// 根据ID删除一条数据
        /// </summary>
        /// <param name="id"></param>
        public static void DeleteByID(int id)
        {
            ConsumableRecordService.DeleteByCID(id);
            System.Threading.Thread.Sleep(200);
            ConsumableService.DeleteByID(id);
        }

        /// <summary>
        /// 更新一条数据的库存信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Update(Model.Consumable model,DateTime date)
        {
            Model.ConsumableRecord m = new Model.ConsumableRecord();
            m.cid = model.id;
            m.normal = model.normal;
            m.bad = model.bad;
            m.stock = model.stock;
            m.date = date;
            return ConsumableService.Update(model)&&ConsumableRecordService.Add(m);
        }

        /// <summary>
        /// 编辑一条易耗品信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Edit(Model.Consumable model)
        {
            return ConsumableService.Update(model);
        }

        /// <summary>
        /// 根据条件获取数据列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static DataSet GetList(string strWhere = "")
        {
            return ConsumableService.GetList(strWhere);
        }


        /// <summary>
        /// 根据ID获取一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Model.Consumable SelectOneByID(int id)
        {
            return ConsumableService.SelectOneByID(id);
        }
    }
}
